package huixue.cn.com.rxapp.ui;

import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;
import android.view.View;
import android.widget.Button;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import huixue.cn.com.library.util.ToastUtils;
import huixue.cn.com.rxapp.R;
import huixue.cn.com.rxapp.base.SimpleActivity;
import huixue.cn.com.rxapp.service.ComputeService;

public class BinderActivity extends SimpleActivity {

    @BindView(R.id.btn_aidl)
    Button btnAidl;

    private IBinder mRemote = null;

    @Override
    public int getLayout() {
        return R.layout.activity_binder;
    }

    @Override
    public void initView() {

    }
    Intent intent;
    @Override
    public void addEvent() {
         intent = new Intent(this,ComputeService.class);
        //bindService(intent,serviceConnection, Context.BIND_AUTO_CREATE);

    }

    @OnClick({R.id.btn_aidl})
    public void onViewClicked(View view) {

      /* String result =  strcat("abc","HIJ");
       ToastUtils.showToast(result);*/

        startService(intent);
    }


    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mRemote  = service;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    private String strcat(String x, String y) {
        Parcel _data = Parcel.obtain();

        Parcel _reply = Parcel.obtain();
        String _result = null;
        try{
            _data.writeString(x);
            _data.writeString(y);

            mRemote.transact(1, _data, _reply, 0);

            _result = _reply.readString();
        }catch (RemoteException e){

        }finally {
            _data.recycle();
            _reply.recycle();
        }

        return _result;
    }

}
